<?php

namespace addons\qingdongams\model;

use app\admin\model\Admin;
use think\Model;
use traits\model\SoftDelete;

/**
 *联系人表
 */
class QuoteFile Extends Model {

    protected $name = 'qingdongams_quote_file';
	// 开启自动写入时间戳字段
	protected $autoWriteTimestamp = 'int';
	// 定义时间戳字段名
	protected $createTime = false;
	protected $updateTime = false;
	protected $deleteTime = false;

	//附件表
	public function file() {
		return $this->hasOne(File::class, 'id', 'file_id')->with('staff')->bind('id,size,create_staff_id,types,name,file_path,staff');
	}
    public function auth() {
        return $this->hasOne(Admin::class, 'id', 'create_id')->field('id,username,nickname');
    }
	public static function addFiles($files, $quote_id, $createId=0) {

		$files    = explode(',', $files);
		$addFiles = [];
		$now = time();
		foreach ($files as $v) {
			$addFiles[] = [
				'quote_id' => $quote_id,
				'file_id'     => $v,
                'createtime'  => $now,
                'create_id'   => $createId,
			];
		}
		$model=new self();
		if($model->insertAll($addFiles)){
			return true;
		}
		return false;
	}
}
